/*****************************************************************************************
 * FILE NAME: srv_cosmoplat                       COPYRIGHT (c) cos 2024
 * REVISION:  1.0.0                                     All Rights Reserved
 * DESCRIPTION:
 * =======================================================================================
 * UPDATE HISTORY：
 * REV      AUTHOR      DATE
 * v1.0.0   Tuxin       2024.10.14
 * DESCRIPTION OF CHANGE:
 ****************************************************************************************/
#ifndef __SRV_COSMOPLAT_H
#define __SRV_COSMOPLAT_H

//----------------------------------------------------------------------------------------
// @Project Includes
#include "typedefs.h"

//----------------------------------------------------------------------------------------
// @Global Macro Define in the module
#define COSM_PROTOCOL_ADDRESS    				  (0x01)/*通讯地址*/

#define COSM_REG_PARM_MAX_NUM							(1580u)/*最大1580个寄存器*/

#define COSM_PROTOCOL_HEAD     						(0xAA)/*协议头*/
#define COSM_PROTOCOL_TAIL     						(0x55)/*协议尾*/
#define COSM_PROTOCOL_READ     						(0x01)/*读取*/
#define COSM_PROTOCOL_WRITE     					(0x10)/*写入*/

#define COSM_WRITE_STATE_SUCCESS 					(0x00)/*写入状态正确*/
#define COSM_WRITE_STATE_ERROR  					(0x01)/*写入状态非法*/
#define COSM_WRITE_STATE_ADDRESS_ERROR  	(0x02)/*写入状态非法地址*/
#define COSM_WRITE_STATE_OPT_ERROR  			(0x03)/*写入状态非法操作*/

#define COSM_BASICINFO_START_ADDR  				(0x0000)/*基本信息开始地址*/
#define COSM_BASICINFO_END_ADDR    				(0x0072)/*基本信息结束地址*/
#define COSM_REALTIME_START_ADDR 					(0x0100)/*实时信息开始地址*/
#define COSM_REALTIME_END_ADDR   					(0x01A7)/*实时信息结束地址*/
#define COSM_CONFIGPARM_START_ADDR  			(0x0200)/*系统参数开始地址*/
#define COSM_CONFIGPARM_END_ADDR    			(0x0229)/*系统参数结束地址*/
#define COSM_SWPROTECTPARM_START_ADDR  		(0x0300)/*软件保护参数开始地址*/
#define COSM_SWPROTECTPARM_END_ADDR    		(0x03D2)/*软件保护参数结束地址*/
#define COSM_HWPROTECTPARM_START_ADDR  		(0x0500)/*硬件保护参数开始地址*/
#define COSM_HWPROTECTPARM_END_ADDR    		(0x0522)/*硬件保护参数结束地址*/
#define COSM_CALPARM_START_ADDR  					(0x0600)/*标定参数开始地址*/
#define COSM_CALPARM_END_ADDR    					(0x062B)/*标定参数结束地址*/

#define COSM_CMD_SHUTDOWN  								(0x0001)/*关机*/
#define COSM_CMD_DEFAULTFACTORY  					(0x0002)/*恢复出厂*/
#define COSM_CMD_RESET  									(0x0004)/*设备复位（重启系统）*/
#define COSM_CMD_PDSG  										(0x0008)/*空闲*/
#define COSM_CMD_CHGSWITCH  							(0x0010)/*充电MOS控制（开关切换）*/
#define COSM_CMD_DSGSWITCH 								(0x0020)/*放电MOS控制（开关切换）*/
#define COSM_CMD_DELEVENT  								(0x0040)/*删除事件记录（黑匣子）*/
#define COSM_CMD_ENTERTEST  							(0x0080)/*进入出厂测试模式*/
#define COSM_CMD_EXITTEST 								(0x0100)/*退出出厂测试模式*/
#define COSM_CMD_SLEEP  									(0x0200)/*进入休眠*/
#define COSM_CMD_POWERDOWN  							(0x0400)/*进入掉电*/
#define COSM_CMD_CLEFAULT  								(0x0800)/*清除故障*/
#define COSM_CMD_SOC  										(0x1000)/*低于SOC 20%强制打开控制*/
#define COSM_CMD_HEAT  										(0x2000)/*加热开关控制*/
#define COSM_CMD_PCHG  										(0x4000)/*预充开关控制*/
#define COSM_CMD_CLIMIT  									(0x8000)/*限流开关控制*/

#define COSM_CTL_ADDR  										(0x0280)/*系统控制地址*/
#define COSM_BAL_ADDR    									(0x0281)/*均衡控制地址*/

#define COSM_OTA_INFO_ADDR  							(0xE0E0)/*升级索引信息地址*/
#define COSM_OTA_UPDATA_ADDR    					(0xE0E1)/*升级数据更新地址*/
#define COSM_OTA_RESULT_ADDR    					(0xE0E2)/*升级结果查询地址*/
#define COSM_OTA_TIMEOUT		  						(5)/*超时时间5秒*/

#define COSM_EVENT_INDEX_ADDR  						(0xF0F0)/*事件索引信息地址*/
#define COSM_EVENT_DATA_ADDR    					(0xF0F1)/*事件数据获取地址*/

#define COSM_RX_BUF_SIZE									(USART_RS485_MAX_RX_SIZE)
#define COSM_TX_BUF_SIZE      						(USART_RS485_MAX_TX_SIZE)

//----------------------------------------------------------------------------------------
// @Global Type defines in the module
typedef enum en_reg_parm_num
{
    REG_BASIC_SW_VER    			= 0,
    REG_BASIC_HW_VER 					= 15,
    REG_BASIC_DEVIC_ID  			= 30,
    REG_BASIC_FACTORY_ID 			= 46,	
    REG_BASIC_PROJECT_CODE 		= 56,	
    REG_BASIC_BATTERY_NUM 		= 66,	
    REG_BASIC_ICCID_NUM 			= 76,
    REG_BASIC_IMEI_NUM 				= 86,	
    REG_BASIC_PASSWORD 				= 96,	
    REG_BASIC_RTC_TIME 				= 111,	

		/*the realtime address*/
	
    REG_CONFIG_CURSW 					= 512,	
    REG_CONFIG_CURTHR 				= 513,	
    REG_CONFIG_CURTIME 				= 514,		
    REG_CONFIG_CYCLECOUNT 		= 515,	
    REG_CONFIG_PERCHGVOL	 		= 516,	
    REG_CONFIG_AFETYPE 				= 517,	
    REG_CONFIG_INVTYPE 				= 518,	
    REG_CONFIG_BATTERYTYPE 		= 519,	
    REG_CONFIG_CELLS 					= 520,	
    REG_CONFIG_CELLP					= 521,	
    REG_CONFIG_CHGCAB 				= 522,		
    REG_CONFIG_COMMUADDR			= 523,	
    REG_CONFIG_FORBIDCHGVOL 	= 524,	
    REG_CONFIG_MAXCHGCUR 			= 525,	
    REG_CONFIG_FORBIDBALHIGHTTEMPTHR 	= 526,	
    REG_CONFIG_FORBIDBALLOWTEMPTHR 		= 527,
    REG_CONFIG_FULLCHGVOL 		= 528,	
    REG_CONFIG_FULLCHGCUR 		= 529,	
    REG_CONFIG_FULLCHGDURATION	= 530,
    REG_CONFIG_MODFUNC				= 531,
    REG_CONFIG_RANK2FUNC			= 533,
    REG_CONFIG_RANK1FUNC			= 535,
    REG_CONFIG_SAMPRESISTOR		= 537,	
    REG_CONFIG_DISPSOC				= 538,	
    REG_CONFIG_TRUESOC				= 539,
    REG_CONFIG_SOCINTERVAL		= 540,	
    REG_CONFIG_SOH	= 541,	
    REG_CONFIG_DESIGNVOL			= 542,
    REG_CONFIG_DESIGNCAP			= 543,
    REG_CONFIG_FULLCHGCAP			= 545,	
    REG_CONFIG_REMAINCAP			= 547,	
    REG_CONFIG_ACCCHGCAP			= 549,	
    REG_CONFIG_ACCDSGCAP			= 551,	
 
    REG_PROTECT_OV1						= 768,
    REG_PROTECT_OVT1					= 769,
    REG_PROTECT_OVR1					= 770,	
    REG_PROTECT_OVRT1					= 771,	
    REG_PROTECT_OV2						= 772,
    REG_PROTECT_OVT2					= 773,
    REG_PROTECT_OVR2					= 774,	
    REG_PROTECT_OVRT2					= 775,	
    REG_PROTECT_OV3						= 776,
    REG_PROTECT_OVT3					= 777,
    REG_PROTECT_OVR3					= 778,	
    REG_PROTECT_OVRT3					= 779,	
    REG_PROTECT_UV1						= 780,
    REG_PROTECT_UVT1					= 781,
    REG_PROTECT_UVR1					= 782,	
    REG_PROTECT_UVRT1					= 783,	
    REG_PROTECT_UV2						= 784,
    REG_PROTECT_UVT2					= 785,
    REG_PROTECT_UVR2					= 786,	
    REG_PROTECT_UVRT2					= 787,	
    REG_PROTECT_UV3						= 788,
    REG_PROTECT_UVT3					= 789,
    REG_PROTECT_UVR3					= 790,	
    REG_PROTECT_UVRT3					= 791,	
    REG_PROTECT_BALOPENV			= 792,	
    REG_PROTECT_BALOPEND			= 793,	
    REG_PROTECT_BALOPENT			= 794,	
    REG_PROTECT_BALCLOSEV			= 795,	
    REG_PROTECT_BALCLOSED			= 796,	
    REG_PROTECT_BALCLOSET			= 797,
    REG_PROTECT_OCCV1					= 798,
    REG_PROTECT_OCCT1					= 799,
    REG_PROTECT_OCCRV1				= 800,	
    REG_PROTECT_OCCRT1				= 801,
    REG_PROTECT_OCCV2					= 802,
    REG_PROTECT_OCCT2					= 803,
    REG_PROTECT_OCCRV2				= 804,	
    REG_PROTECT_OCCRT2				= 805,
    REG_PROTECT_OCCV3					= 806,
    REG_PROTECT_OCCT3					= 807,
    REG_PROTECT_OCCRV3				= 808,	
    REG_PROTECT_OCCRT3				= 809,
    REG_PROTECT_OCDV1					= 810,
    REG_PROTECT_OCDT1					= 811,
    REG_PROTECT_OCDRV1				= 812,	
    REG_PROTECT_OCDRT1				= 813,
    REG_PROTECT_OCDV2					= 814,
    REG_PROTECT_OCDT2					= 815,
    REG_PROTECT_OCDRV2				= 816,	
    REG_PROTECT_OCDRT2				= 817,
    REG_PROTECT_OCDV3					= 818,
    REG_PROTECT_OCDT3					= 819,
    REG_PROTECT_OCDRV3				= 820,	
    REG_PROTECT_OCDRT3				= 821,
    REG_PROTECT_OTC1					= 822,
    REG_PROTECT_OTCT1					= 823,
    REG_PROTECT_OTCR1					= 824,	
    REG_PROTECT_OTCRT1				= 825,
    REG_PROTECT_OTC2					= 826,
    REG_PROTECT_OTCT2					= 827,
    REG_PROTECT_OTCR2					= 828,	
    REG_PROTECT_OTCRT2				= 829,		
    REG_PROTECT_OTC3					= 830,
    REG_PROTECT_OTCT3					= 831,
    REG_PROTECT_OTCR3					= 832,	
    REG_PROTECT_OTCRT3				= 833,		
    REG_PROTECT_UTC1					= 834,
    REG_PROTECT_UTCT1					= 835,
    REG_PROTECT_UTCR1					= 836,	
    REG_PROTECT_UTCRT1				= 837,
    REG_PROTECT_UTC2					= 838,
    REG_PROTECT_UTCT2					= 839,
    REG_PROTECT_UTCR2					= 840,	
    REG_PROTECT_UTCRT2				= 841,		
    REG_PROTECT_UTC3					= 842,
    REG_PROTECT_UTCT3					= 843,
    REG_PROTECT_UTCR3					= 844,	
    REG_PROTECT_UTCRT3				= 845,
    REG_PROTECT_OTD1					= 846,
    REG_PROTECT_OTDT1					= 847,
    REG_PROTECT_OTDR1					= 848,	
    REG_PROTECT_OTDRT1				= 849,
    REG_PROTECT_OTD2					= 850,
    REG_PROTECT_OTDT2					= 851,
    REG_PROTECT_OTDR2					= 852,	
    REG_PROTECT_OTDRT2				= 853,		
    REG_PROTECT_OTD3					= 854,
    REG_PROTECT_OTDT3					= 855,
    REG_PROTECT_OTDR3					= 856,	
    REG_PROTECT_OTDRT3				= 857,		
    REG_PROTECT_UTD1					= 858,
    REG_PROTECT_UTDT1					= 859,
    REG_PROTECT_UTDR1					= 860,	
    REG_PROTECT_UTDRT1				= 861,
    REG_PROTECT_UTD2					= 862,
    REG_PROTECT_UTDT2					= 863,
    REG_PROTECT_UTDR2					= 864,	
    REG_PROTECT_UTDRT2				= 865,		
    REG_PROTECT_UTD3					= 866,
    REG_PROTECT_UTDT3					= 867,
    REG_PROTECT_UTDR3					= 868,	
    REG_PROTECT_UTDRT3				= 869,
    REG_PROTECT_OTCDM1				= 870,
    REG_PROTECT_OTCDMT1				= 871,
    REG_PROTECT_OTCDMR1				= 872,	
    REG_PROTECT_OTCDMRT1			= 873,		
    REG_PROTECT_OTCDM2				= 874,
    REG_PROTECT_OTCDMT2				= 875,
    REG_PROTECT_OTCDMR2				= 876,	
    REG_PROTECT_OTCDMRT2			= 877,			
    REG_PROTECT_OTCDM3				= 878,
    REG_PROTECT_OTCDMT3				= 879,
    REG_PROTECT_OTCDMR3				= 880,	
    REG_PROTECT_OTCDMRT3			= 881,	
    REG_PROTECT_UTCDM1				= 882,
    REG_PROTECT_UTCDMT1				= 883,
    REG_PROTECT_UTCDMR1				= 884,	
    REG_PROTECT_UTCDMRT1			= 885,		
    REG_PROTECT_UTCDM2				= 886,
    REG_PROTECT_UTCDMT2				= 887,
    REG_PROTECT_UTCDMR2				= 888,	
    REG_PROTECT_UTCDMRT2			= 889,			
    REG_PROTECT_UTCDM3				= 890,
    REG_PROTECT_UTCDMT3				= 891,
    REG_PROTECT_UTCDMR3				= 892,	
    REG_PROTECT_UTCDMRT3			= 893,
    REG_PROTECT_OTAMB1				= 894,
    REG_PROTECT_OTAMBT1				= 895,
    REG_PROTECT_OTAMBR1				= 896,	
    REG_PROTECT_OTAMBRT1			= 897,		
    REG_PROTECT_OTAMB2				= 898,
    REG_PROTECT_OTAMBT2				= 899,
    REG_PROTECT_OTAMBR2				= 900,	
    REG_PROTECT_OTAMBRT2			= 901,			
    REG_PROTECT_OTAMB3				= 902,
    REG_PROTECT_OTAMBT3				= 903,
    REG_PROTECT_OTAMBR3				= 904,	
    REG_PROTECT_OTAMBRT3			= 905,
    REG_PROTECT_UTAMB1				= 906,
    REG_PROTECT_UTAMBT1				= 907,
    REG_PROTECT_UTAMBR1				= 908,	
    REG_PROTECT_UTAMBRT1			= 909,		
    REG_PROTECT_UTAMB2				= 910,
    REG_PROTECT_UTAMBT2				= 911,
    REG_PROTECT_UTAMBR2				= 912,	
    REG_PROTECT_UTAMBRT2			= 913,			
    REG_PROTECT_UTAMB3				= 914,
    REG_PROTECT_UTAMBT3				= 915,
    REG_PROTECT_UTAMBR3				= 916,	
    REG_PROTECT_UTAMBRT3			= 917,
    REG_PROTECT_DIFFVOL1			= 918,
    REG_PROTECT_DIFFVOLT1			= 919,
    REG_PROTECT_DIFFVOLR1			= 920,	
    REG_PROTECT_DIFFVOLRT1		= 921,	
    REG_PROTECT_DIFFVOL2			= 922,
    REG_PROTECT_DIFFVOLT2			= 923,
    REG_PROTECT_DIFFVOLR2			= 924,	
    REG_PROTECT_DIFFVOLRT2		= 925,	
    REG_PROTECT_DIFFVOL3			= 926,
    REG_PROTECT_DIFFVOLT3			= 927,
    REG_PROTECT_DIFFVOLR3			= 928,	
    REG_PROTECT_DIFFVOLRT3		= 929,
    REG_PROTECT_TOV1					= 930,
    REG_PROTECT_TOVT1					= 931,
    REG_PROTECT_TOVR1					= 932,	
    REG_PROTECT_TOVRT1				= 933,	
    REG_PROTECT_TOV2					= 934,
    REG_PROTECT_TOVT2					= 935,
    REG_PROTECT_TOVR2					= 936,	
    REG_PROTECT_TOVRT2				= 937,	
    REG_PROTECT_TOV3					= 938,
    REG_PROTECT_TOVT3					= 939,
    REG_PROTECT_TOVR3					= 940,	
    REG_PROTECT_TOVRT3				= 941,	
    REG_PROTECT_TUV1					= 942,
    REG_PROTECT_TUVT1					= 943,
    REG_PROTECT_TUVR1					= 944,	
    REG_PROTECT_TUVRT1				= 945,	
    REG_PROTECT_TUV2					= 946,
    REG_PROTECT_TUVT2					= 947,
    REG_PROTECT_TUVR2					= 948,	
    REG_PROTECT_TUVRT2				= 949,	
    REG_PROTECT_TUV3					= 950,
    REG_PROTECT_TUVT3					= 951,
    REG_PROTECT_TUVR3					= 952,	
    REG_PROTECT_TUVRT3				= 953,	
    REG_PROTECT_DIFFTEMP1			= 954,
    REG_PROTECT_DIFFTEMPT1		= 955,
    REG_PROTECT_DIFFTEMPR1		= 956,	
    REG_PROTECT_DIFFTEMPRT1		= 957,	
    REG_PROTECT_DIFFTEMP2			= 958,
    REG_PROTECT_DIFFTEMPT2		= 959,
    REG_PROTECT_DIFFTEMPR2		= 960,	
    REG_PROTECT_DIFFTEMPRT2		= 961,	
    REG_PROTECT_DIFFTEMP3			= 962,
    REG_PROTECT_DIFFTEMPT3		= 963,
    REG_PROTECT_DIFFTEMPR3		= 964,	
    REG_PROTECT_DIFFTEMPRT3		= 965,
    REG_PROTECT_SOCLOW1				= 966,
    REG_PROTECT_SOCLOWT1			= 967,
    REG_PROTECT_SOCLOWR1			= 968,	
    REG_PROTECT_SOCLOWRT1			= 969,	
    REG_PROTECT_SOCLOW2				= 970,
    REG_PROTECT_SOCLOWT2			= 971,
    REG_PROTECT_SOCLOWR2			= 972,	
    REG_PROTECT_SOCLOWRT2			= 973,	
    REG_PROTECT_SOCLOW3				= 974,
    REG_PROTECT_SOCLOWT3			= 975,
    REG_PROTECT_SOCLOWR3			= 976,	
    REG_PROTECT_SOCLOWRT3			= 977,

    REG_PROTECT_OV						= 1280,
    REG_PROTECT_OVT						= 1281,
    REG_PROTECT_OVR						= 1282,	
    REG_PROTECT_OVRT					= 1283,	
    REG_PROTECT_UV						= 1284,
    REG_PROTECT_UVT						= 1285,
    REG_PROTECT_UVR						= 1286,	
    REG_PROTECT_UVRT					= 1287,	
    REG_PROTECT_OCCV					= 1288,
    REG_PROTECT_OCCT					= 1289,
    REG_PROTECT_OCCRV					= 1290,	
    REG_PROTECT_OCCRT					= 1291,
    REG_PROTECT_OCDV					= 1292,
    REG_PROTECT_OCDT					= 1293,
    REG_PROTECT_OCDRV					= 1294,	
    REG_PROTECT_OCDRT					= 1295,
    REG_PROTECT_SCV						= 1296,	
    REG_PROTECT_SCT						= 1297,		
    REG_PROTECT_OTC						= 1298,
    REG_PROTECT_OTCT					= 1299,
    REG_PROTECT_OTCR					= 1300,	
    REG_PROTECT_OTCRT					= 1301,
    REG_PROTECT_UTC						= 1302,
    REG_PROTECT_UTCT					= 1303,
    REG_PROTECT_UTCR					= 1304,	
    REG_PROTECT_UTCRT					= 1305,
    REG_PROTECT_OTD						= 1306,
    REG_PROTECT_OTDT					= 1307,
    REG_PROTECT_OTDR					= 1308,	
    REG_PROTECT_OTDRT					= 1309,
    REG_PROTECT_UTD						= 1310,
    REG_PROTECT_UTDT					= 1311,
    REG_PROTECT_UTDR					= 1312,	
    REG_PROTECT_UTDRT					= 1313,

    REG_CAL_TEMP							= 1536,
    REG_CAL_VOL								= 1544,	
    REG_CAL_ZEROCUR						= 1576,		
    REG_CAL_RATCHG						= 1577,
    REG_CAL_RATDSG						= 1578,	

}en_reg_parm_num_t;

//----------------------------------------------------------------------------------------
// @Export global Variables declare in the module
extern uint16_t  g_u16RegParm[COSM_REG_PARM_MAX_NUM];

//----------------------------------------------------------------------------------------
// @Export declaration of functions in the module
void srv_cosm_timeout(void);
void srv_cosm_receiveProcess(void);

#endif

// =======================================================================================
// End of file.
// =======================================================================================
